﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Vit.Web.Models;

namespace Vit.Web.Mvc.DataAnnotations
{
    [AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
    public sealed class DataSourceAttribute : AdditionalAttribute
    {
        public DataSourceAttribute(Type dataSourceType)
            : this(dataSourceType, null, true)
        {
        }
        public DataSourceAttribute(Type dataSourceType, string categoryName)
            : this(dataSourceType, categoryName, true)
        {
        }
        public DataSourceAttribute(Type dataSourceType, string categoryName, bool referenceById)
        {
            DataSourceType = dataSourceType;
            CategoryName = categoryName ?? dataSourceType.FullName;
            ReferenceById = referenceById;
        }

        public Type DataSourceType { get; set; }
        public bool ReferenceById { get; set; }
        public string CategoryName { get; set; }
        public string AutoInsertMethod { get; set; }

        public string ShortNameFormat { get; set; }
        public string[] ShortNameColumns { get; set; }
        public string DependOnPropertyName { get; set; }

        public const string AttributeKey = "DataSource";
        public override string AddtionalKey
        {
            get { return AttributeKey; }
        }
    }
}
